package com.sthz.facepay.mapper;

import com.sthz.facepay.model.Member;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

public interface MemberMapper {
    @Delete({
        "delete from st_member",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into st_member (id, pid, ",
        "eid, gid, name, ",
        "sex, birthday, number, ",
        "phone, spare_money, ",
        "last_consume_money, consume_time, ",
        "notice, coupon, ",
        "picture, member_notice, ",
        "gift_points, qq, ",
        "emily, like, address, ",
        "Specifications, garde, ",
        "grouping, anniversaries)",
        "values (#{id,jdbcType=INTEGER}, #{pid,jdbcType=INTEGER}, ",
        "#{eid,jdbcType=INTEGER}, #{gid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{sex,jdbcType=TINYINT}, #{birthday,jdbcType=DATE}, #{number,jdbcType=VARCHAR}, ",
        "#{phone,jdbcType=VARCHAR}, #{spare_money,jdbcType=DOUBLE}, ",
        "#{last_consume_money,jdbcType=DOUBLE}, #{consume_time,jdbcType=TIMESTAMP}, ",
        "#{notice,jdbcType=VARCHAR}, #{coupon,jdbcType=VARCHAR}, ",
        "#{picture,jdbcType=VARCHAR}, #{member_notice,jdbcType=VARCHAR}, ",
        "#{gift_points,jdbcType=INTEGER}, #{qq,jdbcType=VARCHAR}, ",
        "#{emily,jdbcType=VARCHAR}, #{like,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, ",
        "#{specifications,jdbcType=VARCHAR}, #{garde,jdbcType=VARCHAR}, ",
        "#{grouping,jdbcType=VARCHAR}, #{anniversaries,jdbcType=VARCHAR})"
    })
    int insert(Member record);

    @InsertProvider(type=MemberSqlProvider.class, method="insertSelective")
    int insertSelective(Member record);

    @Select({
        "select",
        "id, pid, eid, gid, name, sex, birthday, number, phone, spare_money, last_consume_money, ",
        "consume_time, notice, coupon, picture, member_notice, gift_points, qq, emily, ",
        "like, address, Specifications, garde, grouping, anniversaries",
        "from st_member",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
       /* @Result(column="pid", property="pid", jdbcType=JdbcType.INTEGER),
        @Result(column="eid", property="eid", jdbcType=JdbcType.INTEGER),
        @Result(column="gid", property="gid", jdbcType=JdbcType.INTEGER),*/
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
        @Result(column="birthday", property="birthday", jdbcType=JdbcType.DATE),
        @Result(column="number", property="number", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="spare_money", property="spare_money", jdbcType=JdbcType.DOUBLE),
        @Result(column="last_consume_money", property="last_consume_money", jdbcType=JdbcType.DOUBLE),
        @Result(column="consume_time", property="consume_time", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="notice", property="notice", jdbcType=JdbcType.VARCHAR),
        @Result(column="coupon", property="coupon", jdbcType=JdbcType.VARCHAR),
        @Result(column="picture", property="picture", jdbcType=JdbcType.VARCHAR),
        @Result(column="member_notice", property="member_notice", jdbcType=JdbcType.VARCHAR),
        @Result(column="gift_points", property="gift_points", jdbcType=JdbcType.INTEGER),
        @Result(column="qq", property="qq", jdbcType=JdbcType.VARCHAR),
        @Result(column="emily", property="emily", jdbcType=JdbcType.VARCHAR),
        @Result(column="like", property="like", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="Specifications", property="specifications", jdbcType=JdbcType.VARCHAR),
        @Result(column="garde", property="garde", jdbcType=JdbcType.VARCHAR),
        @Result(column="grouping", property="grouping", jdbcType=JdbcType.VARCHAR),
        @Result(column="anniversaries", property="anniversaries", jdbcType=JdbcType.VARCHAR),
        @Result(column="inid", property="interval", one=@One(select="com.sthz.facepay.mapper.IntervalMapper.getById",fetchType = FetchType.EAGER)),
        @Result(column="exid", property="exchange", one=@One(select="com.sthz.facepay.mapper.ExchangeMapper.getById",fetchType = FetchType.EAGER)),
        @Result(column="goid", property="goods", one=@One(select="com.sthz.facepay.mapper.GoodsMapper.getById",fetchType = FetchType.EAGER))
    })
    Member selectByPrimaryKey(Integer id);

    @UpdateProvider(type=MemberSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Member record);

    @Update({
        "update st_member",
        "set pid = #{pid,jdbcType=INTEGER},",
          "eid = #{eid,jdbcType=INTEGER},",
          "gid = #{gid,jdbcType=INTEGER},",
          "name = #{name,jdbcType=VARCHAR},",
          "sex = #{sex,jdbcType=TINYINT},",
          "birthday = #{birthday,jdbcType=DATE},",
          "number = #{number,jdbcType=VARCHAR},",
          "phone = #{phone,jdbcType=VARCHAR},",
          "spare_money = #{spare_money,jdbcType=DOUBLE},",
          "last_consume_money = #{last_consume_money,jdbcType=DOUBLE},",
          "consume_time = #{consume_time,jdbcType=TIMESTAMP},",
          "notice = #{notice,jdbcType=VARCHAR},",
          "coupon = #{coupon,jdbcType=VARCHAR},",
          "picture = #{picture,jdbcType=VARCHAR},",
          "member_notice = #{member_notice,jdbcType=VARCHAR},",
          "gift_points = #{gift_points,jdbcType=INTEGER},",
          "qq = #{qq,jdbcType=VARCHAR},",
          "emily = #{emily,jdbcType=VARCHAR},",
          "like = #{like,jdbcType=VARCHAR},",
          "address = #{address,jdbcType=VARCHAR},",
          "Specifications = #{specifications,jdbcType=VARCHAR},",
          "garde = #{garde,jdbcType=VARCHAR},",
          "grouping = #{grouping,jdbcType=VARCHAR},",
          "anniversaries = #{anniversaries,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Member record);
}